package com.wsx.rpc.dubbo.plug.filter;

import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.extension.Activate;
import com.alibaba.dubbo.common.utils.StringUtils;
import com.alibaba.dubbo.rpc.*;

/**
 * @author wangshuaixin
 * @Title: com.wsx.rpc.dubbo.plug.filter.TraceFilter
 * @Description: TODO
 * @date 2018/10/31
 */
@Activate(group = {Constants.CONSUMER, Constants.PROVIDER})
public class TraceFilter implements Filter {

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        String config = invocation.getAttachments().get("switch");
        System.out.println("trace :" + config);
        if (StringUtils.isEmpty(config)) {
            System.out.println("trace switch is null and put value");
            invocation.getAttachments().put("switch", "1@127.0.0.1:23098,192.168.40.9:23098");
        }

        return invoker.invoke(invocation);
    }
}
